<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button v-if="isAuth('generator:upktradesubgoodorder:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button v-if="isAuth('generator:upktradesubgoodorder:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="id"
        header-align="center"
        align="center"
        label="主键ID">
      </el-table-column>
      <el-table-column
        prop="tradeOrderId"
        header-align="center"
        align="center"
        label="交易主表ID，取值CATEGORY的ID(数字0：未插入)">
      </el-table-column>
      <el-table-column
        prop="userId"
        header-align="center"
        align="center"
        label="留存字段交易关联用户流水ID，取值USER的ID(数字0：未插入)">
      </el-table-column>
      <el-table-column
        prop="payToolId"
        header-align="center"
        align="center"
        label="用户选择的支付方式的ID,取值表PAY_TOOL表(数字0：未插入)">
      </el-table-column>
      <el-table-column
        prop="consignee"
        header-align="center"
        align="center"
        label="收货人的姓名,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)">
      </el-table-column>
      <el-table-column
        prop="tel"
        header-align="center"
        align="center"
        label="收货人的固定电话,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)">
      </el-table-column>
      <el-table-column
        prop="mobile"
        header-align="center"
        align="center"
        label="收货人的手机,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)">
      </el-table-column>
      <el-table-column
        prop="bestTime"
        header-align="center"
        align="center"
        label="收货人的最佳送货时间,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)">
      </el-table-column>
      <el-table-column
        prop="address"
        header-align="center"
        align="center"
        label="收货人的详细地址,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)">
      </el-table-column>
      <el-table-column
        prop="shippingOrderId"
        header-align="center"
        align="center"
        label="发货物流单号(字符串空：未插入)">
      </el-table-column>
      <el-table-column
        prop="shippingId"
        header-align="center"
        align="center"
        label="用户选择的配送方式ID,取值表SHIPPING(字符串空：未插入)">
      </el-table-column>
      <el-table-column
        prop="shippingTime"
        header-align="center"
        align="center"
        label="订单配送时间(数字0：未插入)">
      </el-table-column>
      <el-table-column
        prop="orderAmount"
        header-align="center"
        align="center"
        label="订单应付款金额即商品总额加配送费加包装费等(数字0：未插入)">
      </el-table-column>
      <el-table-column
        prop="goodsAmount"
        header-align="center"
        align="center"
        label="商品的总金额(数字0：未插入)">
      </el-table-column>
      <el-table-column
        prop="shippingFee"
        header-align="center"
        align="center"
        label="配送费用即外卖系统比较重要(数字0：未插入)">
      </el-table-column>
      <el-table-column
        prop="packFee"
        header-align="center"
        align="center"
        label="包装费用即点餐打包费外卖系统比较重要(数字0：未插入)">
      </el-table-column>
      <el-table-column
        prop="insureFee"
        header-align="center"
        align="center"
        label="保价费用(数字0：未插入)">
      </el-table-column>
      <el-table-column
        prop="bonusTypeId"
        header-align="center"
        align="center"
        label="留存字段优惠方式标识即优惠类型，即红包ID, USER_BONUS的BONUS_ID(数字0：未插入)">
      </el-table-column>
      <el-table-column
        prop="bonusId"
        header-align="center"
        align="center"
        label="优惠类型，即红包ID, USER_BONUS的BONUS_ID(数字0：未插入)">
      </el-table-column>
      <el-table-column
        prop="bonusMoney"
        header-align="center"
        align="center"
        label="优惠额度，即使用红包抵扣的金额(数字0：未插入)">
      </el-table-column>
      <el-table-column
        prop="orderStatus"
        header-align="center"
        align="center"
        label="订单状态(数字0：未插入，1已确认; 2已取消; 3无效; 4退货)">
      </el-table-column>
      <el-table-column
        prop="score"
        header-align="center"
        align="center"
        label="单个商品评分(数字0：未插入)">
      </el-table-column>
      <el-table-column
        prop="goodsNumber"
        header-align="center"
        align="center"
        label="商品数量(数字0：未插入，1.是,2：否，)">
      </el-table-column>
      <el-table-column
        prop="operator"
        header-align="center"
        align="center"
        label="操作员(字符串空：未插入)">
      </el-table-column>
      <el-table-column
        prop="createUtc"
        header-align="center"
        align="center"
        label="创建即上传时间(数字0：未插入)">
      </el-table-column>
      <el-table-column
        prop="modifyUtc"
        header-align="center"
        align="center"
        label="修改即更新时间(数字0：未插入)">
      </el-table-column>
      <el-table-column
        prop="isDeleted"
        header-align="center"
        align="center"
        label="是否删除(数字0：未插入，1.未删除,2：删除，)">
      </el-table-column>
      <el-table-column
        prop="version"
        header-align="center"
        align="center"
        label="版本号(数字0：未插入)">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import API from '@/api'
  import AddOrUpdate from './add-or-update'
  export default {
    data () {
      return {
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        var params = {
          page: this.pageIndex,
          limit: this.pageSize,
          key: this.dataForm.key
        }
        API.upktradesubgoodorder.list(params).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          API.upktradesubgoodorder.del(ids).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>
